

package com.example.administrator.caigou51.recyclerCard.cardView;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.administrator.caigou51.R;
import com.example.administrator.caigou51.global.App;
import com.example.administrator.caigou51.recyclerCard.basic.CardItemView;
import com.example.administrator.caigou51.recyclerCard.basic.MaterialListAdapter;
import com.example.administrator.caigou51.recyclerCard.card.OrderDetail2Card;
import com.example.administrator.caigou51.util.ImageUtil;


public class OrderDetail2CardView extends CardItemView<OrderDetail2Card> implements View.OnClickListener{
 	private Context mContext;
    public OrderDetail2CardView(Context context) {
        super(context);
        mContext=context;
        // TODO Auto-generated constructor stub
    }

    public OrderDetail2CardView(Context context, AttributeSet attrs) {
        super(context, attrs);
        mContext=context;
        // TODO Auto-generated constructor stub
    }

    public OrderDetail2CardView(Context context,
                                    AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        mContext=context;
        // TODO Auto-generated constructor stub
    }
    private RelativeLayout relativeLayoutOneGoods;
    private ImageView imageViewGoods;
    private TextView textViewGoodsName;
    private TextView textViewMoneyIcon;
    private TextView textViewGoodsPrice;
    private TextView textViewGoodsCount;
    private LinearLayout linearLayoutShowMore;
    private LinearLayout linearLayoutCloseMore;
    private OrderDetail2Card card;
    @Override
    public void build(OrderDetail2Card card) {
        // TODO Auto-generated method stub
        super.build(card);
        this.card=card;
        relativeLayoutOneGoods = (RelativeLayout) findViewById(R.id.relativeLayoutOneGoods);
        imageViewGoods = (ImageView) findViewById(R.id.imageViewGoods);
        textViewGoodsName = (TextView) findViewById(R.id.textViewGoodsName);
        textViewMoneyIcon = (TextView) findViewById(R.id.textViewMoneyIcon);
        textViewGoodsPrice = (TextView) findViewById(R.id.textViewGoodsPrice);
        textViewGoodsCount = (TextView) findViewById(R.id.textViewGoodsCount);
        linearLayoutShowMore = (LinearLayout) findViewById(R.id.linearLayoutShowMore);
        linearLayoutCloseMore = (LinearLayout) findViewById(R.id.linearLayoutCloseMore);

        App.displayImageHttpOrFile(card.getGoodsEntity().getThumb(),imageViewGoods, ImageUtil.OptionsActivity());
        textViewGoodsName.setText(card.getGoodsEntity().getTitle()+card.getGoodsEntity().getProduct_spec());
        textViewGoodsPrice.setText(card.getGoodsEntity().getPrice());
        textViewGoodsCount.setText("数量:"+card.getGoodsEntity().getNumber());

       if (card.isShowClose())
       {
           linearLayoutCloseMore.setVisibility(View.VISIBLE);
       }else
       {
           linearLayoutCloseMore.setVisibility(View.GONE);
       }
        if (card.isShowMore())
        {
            linearLayoutShowMore.setVisibility(View.VISIBLE);
        }else
        {
            linearLayoutShowMore.setVisibility(View.GONE);
        }
        linearLayoutCloseMore.setOnClickListener(this);
        linearLayoutShowMore.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId())
        {
            case R.id.linearLayoutCloseMore:
                MaterialListAdapter materialListAdapter= (MaterialListAdapter) card.getMaterialListView().getAdapter();
                for (int i=card.getOrderDetailBean().getGoods().size()-1;i>2;i--)
                {
                    OrderDetail2Card orderDetail1Card2 = new OrderDetail2Card(mContext);
                    orderDetail1Card2.setOrderDetailBean(card.getOrderDetailBean());
                    orderDetail1Card2.setMaterialListView(card.getMaterialListView());
                    orderDetail1Card2.setGoodsEntity(card.getOrderDetailBean().getGoods().get(i));
                    if (i==3) {
                        orderDetail1Card2.setShowClose(true);
                    }

                    int count=materialListAdapter.getAllList().size()-2;
                    materialListAdapter.getAllList().remove(count);

                }
                //取出第三张卡设置可以看见更多
                OrderDetail2Card thirdCard= (OrderDetail2Card) materialListAdapter.getAllList().get(3);
                thirdCard.setShowMore(true);
                card.getMaterialListView().getAdapter().notifyDataSetChanged();
                break;
            case R.id.linearLayoutShowMore:
                MaterialListAdapter materialListAdapter2= (MaterialListAdapter) card.getMaterialListView().getAdapter();
                for (int i=3;i<card.getOrderDetailBean().getGoods().size();i++)
                {
                    OrderDetail2Card orderDetail1Card2 = new OrderDetail2Card(mContext);
                    orderDetail1Card2.setOrderDetailBean(card.getOrderDetailBean());
                    orderDetail1Card2.setMaterialListView(card.getMaterialListView());
                    orderDetail1Card2.setGoodsEntity(card.getOrderDetailBean().getGoods().get(i));
                    if (i==card.getOrderDetailBean().getGoods().size()-1) {
                        orderDetail1Card2.setShowClose(true);
                    }

                    int count=materialListAdapter2.getAllList().size()-1;
                    materialListAdapter2.getAllList().add(count,orderDetail1Card2);

                }
                card.setShowMore(false);
                card.getMaterialListView().getAdapter().notifyDataSetChanged();
                break;
        }
    }
}
